
export default class msfor {
    #list;
    #endfor;
    #index=-1;
    #callback;
    isObject(value) {
        return value != null && value != undefined && value.constructor == Object
    }
    constructor(list = [], end = () => { }) {
      
        if (this.isObject(list)) {
            var ls = [];
            for (var k in list) {
                ls.push(list[k])
            }
            this.#list  = ls;
        }else{
          this.#list = list;
          
        }
        
        this.#endfor = end;
        
    }
    next() {
        this.#index++;
        const self=this;
        const i=this.#index;
        if (this.#list.length <= i) {
            this.#endfor();
            return
        } else {
            this.#callback(this.#list[i],()=>{
              
              self.next()
              
            })
        }
    }
    run(Callback) {
      
        this.#callback = Callback;
        this.next()
    }
}
